package com.ganee.agora.viewmodel

import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import com.alibaba.android.arouter.launcher.ARouter
import com.ganee.agora.model.*

import com.ganee.agora.repository.DetailRepository
import com.ganee.agora.repository.SettingsRepository
import com.ganee.baselib.arouter.Constance
import com.ganee.baselib.httprequest.callback.RequestCallback
import com.ganee.baselib.httprequest.utils.ToastUtil
import com.ganee.baselib.mvvmlibrary.base.BaseViewModel
import okhttp3.RequestBody

class DetailViewModel(application: Application) : BaseViewModel<DetailRepository>(application) {

    var detail = MutableLiveData<DetailEntity>()
    var clientTokenEntity = MutableLiveData<ClientTokenEntity>()
    var recommendList = MutableLiveData<List<InsertActivityEntity>>()
    var commentList = MutableLiveData<List<CommentEntity>>()
    var inviteInfoEntity = MutableLiveData<InviteInfoEntity>()
    var enroll = MutableLiveData<Any>()

    override fun getRepository(): DetailRepository {
        return DetailRepository(this)
    }

       //请求详情
    fun getDetailInfo(body: RequestBody) {
        mRepository.postDetailInfo(body, RequestCallback<DetailEntity> { entity ->
            detail.value = entity
        })
    }

    //请求详情
    fun getRecommendList() {
        mRepository.getRecommendList(RequestCallback<List<InsertActivityEntity>> {
            recommendList.value = it
        })
    }
    //请求详情
    fun getCommentList(body:RequestBody) {
        mRepository.getCommentList(body,RequestCallback<List<CommentEntity>> {
            commentList.value = it
        })
    }

    //请求token
    fun getClientToken(body: RequestBody) {
        mRepository.getClientToken(body,RequestCallback<ClientTokenEntity> {
            clientTokenEntity.value = it
        })
    }

    //支付
    fun postExecutePay(body: RequestBody) {
        mRepository.postExecutePay(body, RequestCallback<String> {
            ToastUtil.showToast("Pay successfully")
        })
    }

    //收藏
    fun postCollect(body: RequestBody) {
        mRepository.postCollect(body, RequestCallback<Any> {
            ToastUtil.showToast("Successful Collection")
        })
    }

    //取消收藏
    fun postCancelCollect(body: RequestBody) {
        mRepository.postCancelCollect(body, RequestCallback<Any> {
            ToastUtil.showToast("Cancel the Collection")
        })
    }

    //请求详情
    fun getInviteInfo(body:RequestBody) {
        mRepository.getInviteInfo(body,RequestCallback<InviteInfoEntity> {
            inviteInfoEntity.value = it
        })
    }
    //免费报名
    fun postEnroll(body:RequestBody) {
        mRepository.postEnroll(body,RequestCallback<Any> {
            enroll.value = it
        })
    }
}
